package com.mdd.common.entity.yangyangLeadingEnterprise.common;



import com.alipay.service.schema.util.StringUtil;
import com.google.gson.Gson;


public class Serializer<T> {

	
	

	public  String toString(T bean) 
	{
		try
		{
			Gson gson=new Gson();
			String s1=gson.toJson(bean);
			//System.out.println(s1);
			return Encrypt.encode(s1.getBytes("UTF8"));
			}catch(Exception e)
			{
				System.out.println(e);
			}
		return null;
	}
	
	public  T toObject(String data,Class<T> clazz)
	{
		//System.out.println(data);
		
		if(StringUtil.isEmpty(data)) return null;
		
		try
		{
		Gson gson=new Gson();		
	
		String a=new String(Encrypt.decode(data),"UTF8");
		//System.out.println(a);
		return gson.fromJson(a, clazz);
		}catch(Exception e)
		{
			System.out.println(e);
			
		}
		return null;
	}
	

	
}
